package cn.com.git.example.common.util.lock;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author zhangzhenfu
 * @Description
 * @date 2020/3/24 9:55
 */
public class LockUtil {

    public static final Integer LOCK_TIME = 3;//加锁等待时间3秒
    private static Map<String,Lock> lockMap = new ConcurrentHashMap<>();

    /**
     * 获取锁
     * @param key
     * @return
     */
    public static Lock getLock(String key) {
        if(!lockMap.containsKey(key)){
            lockMap.put(key,new ReentrantLock());
        }
        return lockMap.get(key);
    }
}
